package com.wh.controller.initial;

import com.wh.pojo.Location;
import com.wh.pojo.LocationType;
import com.wh.pojo.Storehouse;
import com.wh.service.initial.LocationService;
import com.wh.vo.PageResult;
import com.wh.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/location/")
public class LocationController {

    @Autowired
    private LocationService locationService;

    @GetMapping("list")
    public SysResult getLocationList(PageResult pageResult){
        pageResult = locationService.getLocationList(pageResult);
        return SysResult.success(pageResult);
    }

    @PostMapping("addLocation")
    public SysResult addLocation(@RequestBody Location location){
        locationService.addLocation(location);
        return SysResult.success();
    }

    @PutMapping("updataLocation")
    public SysResult updataLocation(@RequestBody Location location){
        locationService.updataLocation(location);
        return SysResult.success();
    }

    @DeleteMapping("delete/{name}")
    public SysResult deleteLocation(@PathVariable String name){
        locationService.deleteLocation(name);
        return SysResult.success();
    }

    @GetMapping("getStorehouse")
    public SysResult getStorehouse(){
        List<Storehouse> storehouseList =  locationService.getStorehouse();
        return SysResult.success(storehouseList);
    }

    @GetMapping("getType")
    public SysResult getType(){
        List<LocationType> locationTypeList = locationService.getType();
        return SysResult.success(locationTypeList);
    }
}
